from datetime import datetime
from django.http import HttpResponse, JsonResponse
from django.shortcuts import render

# Create your views here.


def header(request):
    return render(request, 'baidu.html')

    # 默认响应html内容
    # return HttpResponse(content="hello", status=206, content_type="text/html")
    # 返回图片
    # content = open("/Users/szh/Downloads/1.png", "rb").read()
    # return HttpResponse(content=content, status=206, content_type="image/png")
    # 返回json
    # content = {"name":"haha"}
    # return JsonResponse(content)
    # 返回list转json
    # content = [{"name":"haha"}, {"name":"hehe"}]
    # return JsonResponse(content, safe=False)
    # 自定义响应头
    # rep = HttpResponse("hello")
    # rep["current_time"] = datetime.now().timestamp()
    # return rep

    # res = request.headers  # 获取请求头
    # result = []
    # for k, v in res.items():
    #     result.append(f"'{k}': '{v}'<br>")
    # # print(result)  # 获取请求头
    # return HttpResponse(result)

    # print(request.method)
    # print(request.path)
    # print(request.GET)  # 获取请求的参数字典
    # print(request.GET.get("key"))
    # print(request.GET.getlist("key"))
    # print(request.GET.dict())
    # return HttpResponse("hello")


def templ(request):
    data = {
        'name': "ZHANGsan",
        'name1': "zhang",
        'age': 30,
        'likes': ["电影", "游戏", "美食"],
        'address': {"city": "深圳", "province": "广东"},
        'birth': datetime.now(),
        'html': '<b>jia cu</b>',
        'stars': [
            ["一一", "二二", "三三"],
            ["四四", "五五", "六六"],
            ["七七", "八八", "九九"],
        ]
    }
    return render(request, 'index.html', data)


def block(request):
    return render(request, 'block.html')


def child(request):
    return render(request, 'child.html')